package cn.xo68.metadata.mapper;


import cn.xo68.metadata.entity.MetadataTable;
import org.apache.ibatis.annotations.*;
import java.util.List;

/** 
 * MetadataTable mybatis mapper
 * @author wuyy(16349023@qq.com)
 * @date 2020年03月12日 11:44:16
 *
 */
public interface MetadataTableMapper {


	
	@Select("SELECT * FROM metadata_table WHERE table_id = #{tableId}")
    @Results(value = { 
    @Result(id = true, column = "table_id", property = "tableId"),
        @Result(column = "project_id", property = "projectId"),
        @Result(column = "table_name", property = "tableName"),
        @Result(column = "table_code", property = "tableCode"),
        @Result(column = "comment", property = "comment"),
        @Result(column = "create_time", property = "createTime"),
        @Result(column = "update_time", property = "updateTime")
    })
    MetadataTable find(@Param("tableId") Integer tableId);
	
	@Select("SELECT * FROM metadata_table")
    @Results(value = { 
    @Result(id = true, column = "table_id", property = "tableId"),
        @Result(column = "project_id", property = "projectId"),
        @Result(column = "table_name", property = "tableName"),
        @Result(column = "table_code", property = "tableCode"),
        @Result(column = "comment", property = "comment"),
        @Result(column = "create_time", property = "createTime"),
        @Result(column = "update_time", property = "updateTime")
    })
    List<MetadataTable> list();
	
	@Insert("insert into metadata_table (table_id ,project_id ,table_name ,table_code ,comment ,create_time ,update_time ) values (#{tableId} , #{projectId} , #{tableName} , #{tableCode} , #{comment} , #{createTime} , #{updateTime}  )")
    @SelectKey(statement="SELECT LAST_INSERT_ID()", keyProperty="tableId", before=false, resultType=Integer.class)
    @Options(useGeneratedKeys = true, keyProperty = "tableId")
    int insert(MetadataTable metadataTable);
	
	@Update({"update metadata_table set",
      " project_id=#{projectId}, table_name=#{tableName}, table_code=#{tableCode}, comment=#{comment}, create_time=#{createTime}, update_time=#{updateTime} ",
      "where table_id = #{tableId}"
    })
    int update(MetadataTable metadataTable);

	@Delete("delete FROM metadata_table WHERE table_id = #{tableId}")
	int delete(@Param("tableId") Integer tableId);
}